#include "rgb.h"


void rgb_led_init(void)
{
    led_clk_enable();
    GPIOC->CRL &= ~((unsigned int)0xF << (6 * 4)); // GPIOC_6配置
    GPIOC->CRL |= (unsigned int)0x3 << (6 * 4); 
    GPIOC->CRL &= ~((unsigned int)0xF << (7 * 4)); // GPIOC_7配置
    GPIOC->CRL |= (unsigned int)0x3 << (7 * 4); 
    GPIOC->CRH &= ~((unsigned int)0xF << (0 * 4)); // GPIOC_8配置
    GPIOC->CRH |= (unsigned int)0x3 << (0 * 4);
    led_r(1);
    led_g(1);
    led_b(1);
}

// 白光翻转
void rgb_toggle(void)
{
    
    GPIO_ReadOutputDataBit(led_port,led_r_pin) ? led_r(0) : led_r(1);
    GPIO_ReadOutputDataBit(led_port,led_g_pin) ? led_g(0) : led_g(1);
    GPIO_ReadOutputDataBit(led_port,led_b_pin) ? led_b(0) : led_b(1);
}

// 设置颜色
void set_rgb(color rgb)
{
    led_r(~rgb & 0x04);
    led_g(~rgb & 0x02);
    led_b(~rgb & 0x01);
}
